package com.sky.alogrithm.chapter01_data_structure;

public class Queue<T> {

    private Node first;
    private Node last;
    private int N;

    private class Node{
        T t;
        Node next;
    }

    public boolean isEmpty(){
        return first == null;
    }

    public int size(){
        return N;
    }

    public void enqueue(T t){
        Node oldLast = last;
        last = new Node();
        last.t = t;
        last.next = null;
        if(isEmpty()){
            first = last;
        }else{
            oldLast.next = last;
        }
        N++;
    }

    public T dequeue(){
        T t = first.t;
        first = first.next;
        if(isEmpty()){
            last = null;
        }
        N--;
        return t;
    }
}
